﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：DbContenxtHelper.cs
// 功能描述：TongTongMall.Dapper
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Domain;
using TongTongMall.Domain.Repositories.Entities;
using TongTongMall.Reflection;

namespace TongTongMall.Dapper.DbHelper
{
    internal static class DbContextHelper
    {
        public static IEnumerable<EntityTypeInfo> GetEntityTypeInfos(Type dbContextType)
        {
            return
                    from property in dbContextType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                    where
                        (ReflectionHelper.IsAssignableToGenericType(property.PropertyType, typeof(IModelSet<>))) &&
                        ReflectionHelper.IsAssignableToGenericType(property.PropertyType.GenericTypeArguments[0], typeof(IEntity<>))
                    select new EntityTypeInfo(property.PropertyType.GenericTypeArguments[0], property.DeclaringType);
        }
    }
}
